package com.google.jessewilson.codesearch.util;

import java.util.Iterator;

/**
 * More along the lines of {@link java.util.Collections}.
 *
 * @author jessewilson
 */
public class MoreCollections {

  /**
   * Remove the object by identity.
   *
   * @returns {@code true} if a change was made.
   */
  public static <T> boolean removeByIdentity(Iterable<T> iterable, T toRemove) {
    for (Iterator<T> i = iterable.iterator(); i.hasNext(); ) {
      if (i.next() == toRemove) {
        i.remove();
        return true;
      }
    }
    return false;
  }
}
